package com.zdp.service.impl.center;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdp.common.domain.PagedGridResult;
import com.zdp.mapper.OrdersMapperCustom;
import com.zdp.pojo.vo.MyOrdersVO;
import com.zdp.service.center.MyOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sesshomaru
 * @date 2021/8/14 20:27
 */
@Service
public class MyOrdersServiceImpl implements MyOrdersService {

    @Autowired
    private OrdersMapperCustom ordersMapperCustom;

    @Override
    public PagedGridResult queryMyOrders(String userId, Integer orderStatus, Integer current, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("orderStatus", orderStatus);

        Page<MyOrdersVO> page = new Page<>(current, pageSize);

        List<MyOrdersVO> list = ordersMapperCustom.queryMyOrders(page, map);

        page.setRecords(list);

        return setterPagedGrid(page);
    }

    private PagedGridResult setterPagedGrid(Page<?> page) {
        PagedGridResult grid = new PagedGridResult();
        // 当前页数
        grid.setPage(page.getSize());
        // 总记录数
        grid.setRecords(page.getTotal());
        // 总页数
        grid.setTotal(page.getPages());
        // 实际内容
        grid.setRows(page.getRecords());
        return grid;
    }
}
